
import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/service/Path.dart';
import 'package:im_app/im/socket/dto/business/Message.dart';
import 'package:im_app/im/socket/dto/business/PullData.dart';
import 'package:im_app/im/socket/dto/business/RpcData.dart';


void main() {
	test("encode pull message", () {
		DepartmentInfoListReq departmentInfoListReq = new DepartmentInfoListReq();
		departmentInfoListReq.pageSize = 1000;
		RpcData rpcData2 = RpcData.data("pullDepartments", departmentInfoListReq, "123");
		String dataJson = jsonEncode(rpcData2.data);
		print("data json : $dataJson");
	});

	test("decode pull message", () {
		String json = '''{
				"departmentInfoItemList": [
					{
						"orgCode": "demo",
						"departmentName": "demo"
					},
					{
						"orgCode": "java",
						"departmentName": "java"
					}
				]
			}''';
		DepartmentInfoListItem departmentInfoListItem = DepartmentInfoListItem.fromJson(jsonDecode(json));
		print("data json : ${departmentInfoListItem.toJson()}");
	});

	test("decode pull userInfo", () {
		String json = '''{
		   "userInfoItemList": [
			 {
			   "userId": "2222",
			   "userName": "2222",
			   "sex": "1",
			   "departmentCode": "demo"
			 },
			 {
			   "userId": "test",
			   "userName": "test",
			   "sex": "1",
			   "departmentCode": "demo"
			 },
			 {
			   "userId": "test000",
			   "userName": "test000",
			   "sex": "2",
			   "departmentCode": "demo"
			 },
			 {
			   "userId": "test001",
			   "userName": "test001",
			   "sex": "1",
			   "departmentCode": "demo"
			 },
			 {
			   "userId": "test0010",
			   "userName": "test0010",
			   "sex": "2",
			   "departmentCode": "demo"
			 }
		   ]
		}''';
		UserInfoListItem userInfoListItem = UserInfoListItem.fromJson(jsonDecode(json));
		print("data json : ${userInfoListItem.toJson()}");
	});

	test("comapre", () {
		List list = ["test00100", "test00120", "test1", "2222"];
		list.sort((left, right)=>right.compareTo(left));
		print("list ： $list");

		var vv = ImPath.login.name;
		print("name : $vv");
	});

	test("decode messageObject", () {
		MessageObject messageObject = MessageObject.simple("test00100", "hello world", MessageType.Text);
		messageObject.toUserId = 'test00101';
		String json = jsonEncode(messageObject);
		print("data json : ${json}");
	});

	test("decode pull group info", () {
		String json = '''{
			"groupInfoItemList": [
				{
					"groupId": "818fd81b-5337-40cf-a3e3-ee12e3580a6a",
					"groupName": "测试群1",
					"groupDesc": "as",
					"groupUserSet": [
						{
							"userId": "test00124",
							"status": "1"
						},
						{
							"userId": "test00304",
							"status": "2"
						},
						{
							"userId": "test00126",
							"status": "3"
						},
						{
							"userId": "test00308",
							"status": "4"
						}
					]
				},
				{
					"groupId": "d950f0aa-7bae-4b6f-9e89-08f41e3a408b",
					"groupName": "测试群2",
					"groupUserSet": [
						{
							"userId": "test00123",
							"status": "1"
						},
						{
							"userId": "test00131",
							"status": "2"
						},
						{
							"userId": "test00126",
							"status": "3"
						},
						{
							"userId": "test00100",
							"status": "4"
						},
						{
							"userId": "test00641",
							"status": "2"
						},
						{
							"userId": "test00300",
							"status": "3"
						},
						{
							"userId": "test00230",
							"status": "4"
						}
					]
				},
				{
					"groupId": "cdcf8aa9-be29-4722-89cb-164fc14e6802",
					"groupName": "测试群21",
					"groupUserSet": [
						{
							"userId": "test00782",
							"status": "1"
						},
						{
							"userId": "test00366",
							"status": "2"
						},
						{
							"userId": "test00641",
							"status": "3"
						},
						{
							"userId": "test00100",
							"status": "4"
						}
					]
				}]
		}''';
		GroupInfoListItem groupInfoListItem = GroupInfoListItem.fromJson(jsonDecode(json));
		var groupUser = groupInfoListItem.groupInfoItemList[0].groupUserSet!.toList()[0];
		print("data json ${groupUser.toJson()}");
		print("data json : ${groupInfoListItem.groupInfoItemList[0].toJson()}");
	});

	test("decode DepartmentListItem", () {
		DepartmentInfoListItem departmentInfoListItem = DepartmentInfoListItem([]);
		String json = jsonEncode(departmentInfoListItem);
		print("data json : ${json}");
	});

	test("decode MessageGroupListItem", () {
		String json = '''{
				"messageGroupItemList": [
					{
						"userId": "test00105",
						"isTop": false,
						"isDisturb": false
					},
					{
						"userId": "test00383",
						"isTop": false,
						"isDisturb": false
					}]
			}''';
		SessionItemList sessionItemList = SessionItemList.fromJson(jsonDecode(json));
		print("data json : ${sessionItemList.toJson()}");
	});
}